home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWRgnShp.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  12.9 KB  |  433 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRgnShp.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWRGNSHP_H
  13. #include "FWRgnShp.h"
  14. #endif
  15.  
  16. #ifndef FWDFAULT_H
  17. #include "FWDfault.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWGRUTIL_H
  25. #include "FWGrUtil.h"
  26. #endif
  27.  
  28. #ifndef FWOVLSHP_H
  29. #include "FWOvlShp.h"
  30. #endif
  31.  
  32. #ifndef FWRRCSHP_H
  33. #include "FWRRcShp.h"
  34. #endif
  35.  
  36. #ifndef FWARCSHP_H
  37. #include "FWArcShp.h"
  38. #endif
  39.  
  40. #ifndef FWLINSHP_H
  41. #include "FWLinShp.h"
  42. #endif
  43.  
  44. #ifndef FWRECSHP_H
  45. #include "FWRecShp.h"
  46. #endif
  47.  
  48. // ----- OpenDoc Includes -----
  49.  
  50. #ifndef _TRNSFORM_
  51. #include <Trnsform.h>
  52. #endif
  53.  
  54. //==============================================================================
  55. //    •• RunTime Info
  56. //==============================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment fwgraphx
  60. #endif
  61.  
  62. //==============================================================================
  63. //    •• class FW_CRegionShape
  64. //==============================================================================
  65.  
  66. //------------------------------------------------------------------------------
  67. // FW_CRegionShape::FW_CRegionShape
  68. //------------------------------------------------------------------------------
  69.  
  70. FW_CRegionShape::FW_CRegionShape() :
  71.     FW_CShape()
  72. {
  73. }
  74.  
  75. //------------------------------------------------------------------------------
  76. // FW_CRegionShape::FW_CRegionShape
  77. //------------------------------------------------------------------------------
  78.  
  79. FW_CRegionShape::FW_CRegionShape(XMPShape* xmpShape) :
  80.     FW_CShape()
  81. {
  82.     SetRep(new FW_CRegionShapeRep(xmpShape));
  83. }
  84.  
  85. //------------------------------------------------------------------------------
  86. // FW_CRegionShape::FW_CRegionShape
  87. //------------------------------------------------------------------------------
  88.  
  89. FW_CRegionShape::FW_CRegionShape(const FW_CRect& rect) :
  90.     FW_CShape()
  91. {
  92.     SetRep(new FW_CRegionShapeRep(rect));
  93. }
  94.  
  95. //------------------------------------------------------------------------------
  96. // FW_CRegionShape::FW_CRegionShape
  97. //------------------------------------------------------------------------------
  98.  
  99. FW_CRegionShape::FW_CRegionShape(const FW_CRegionShape& other) :
  100.     FW_CShape(other)
  101. {
  102. }
  103.  
  104. //------------------------------------------------------------------------------
  105. // FW_CRegionShape::FW_CRegionShape
  106. //------------------------------------------------------------------------------
  107.  
  108. FW_CRegionShape::FW_CRegionShape(FW_CRegionShapeRep* rep) :
  109.     FW_CShape(rep)
  110. {
  111. }
  112.  
  113. //------------------------------------------------------------------------------
  114. // FW_CRegionShape::operator=
  115. //------------------------------------------------------------------------------
  116.  
  117. FW_CRegionShape& FW_CRegionShape::operator=(const FW_CRegionShape& other)
  118. {
  119.     SetRep(other.GetRep());
  120.     return *this;
  121. }
  122.  
  123. //------------------------------------------------------------------------------
  124. // FW_CRegionShape::operator=
  125. //------------------------------------------------------------------------------
  126.  
  127. FW_CRegionShape& FW_CRegionShape::operator=(FW_CRegionShapeRep* other)
  128. {
  129.     SetRep(other);
  130.     return *this;
  131. }
  132.  
  133. //------------------------------------------------------------------------------
  134. // FW_CRegionShape::operator FW_COvalShape
  135. //------------------------------------------------------------------------------
  136.  
  137. FW_CRegionShape::operator FW_COvalShape() const
  138. {    
  139.     FW_COvalShape ovalShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  140.     ovalShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  141.     return ovalShape;
  142. }
  143.  
  144. //------------------------------------------------------------------------------
  145. // FW_CRegionShape::operator FW_CRoundRectShape
  146. //------------------------------------------------------------------------------
  147.  
  148. FW_CRegionShape::operator FW_CRoundRectShape() const
  149. {    
  150.     FW_CRoundRectShape roundRectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), FW_kZeroPoint);
  151.     roundRectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  152.     return roundRectShape;
  153. }
  154.  
  155. //------------------------------------------------------------------------------
  156. // FW_CRegionShape::operator FW_CArcShape
  157. //------------------------------------------------------------------------------
  158.  
  159. FW_CRegionShape::operator FW_CArcShape() const
  160. {    
  161.     FW_CArcShape arcShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), 0, 0);
  162.     arcShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  163.     return arcShape;
  164. }
  165.  
  166. //------------------------------------------------------------------------------
  167. // FW_CRegionShape::operator FW_CLineShape
  168. //------------------------------------------------------------------------------
  169.  
  170. FW_CRegionShape::operator FW_CLineShape() const
  171. {    
  172.     FW_CRect rect = ((FW_CShapeRep*)GetRep())->GetShapeBounds();
  173.     FW_CLineShape lineShape(rect[FW_kTopLeft], rect[FW_kBotRight]);
  174.     lineShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  175.     return lineShape;
  176. }
  177.  
  178. //------------------------------------------------------------------------------
  179. // FW_CRegionShape::operator FW_CRectShape
  180. //------------------------------------------------------------------------------
  181.  
  182. FW_CRegionShape::operator FW_CRectShape() const
  183. {    
  184.     FW_CRectShape rectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  185.     rectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  186.     return rectShape;
  187. }
  188.  
  189. //==============================================================================
  190. //    •• class FW_CRegionShapeRep
  191. //==============================================================================
  192.  
  193. //------------------------------------------------------------------------------
  194. //    • FW_CRegionShapeRep::FW_CRegionShapeRep
  195. //------------------------------------------------------------------------------
  196.  
  197. FW_CRegionShapeRep::FW_CRegionShapeRep() :
  198.     FW_CShapeRep(gGraphicGlobales.gRegion),
  199.     fXMPShape(NULL)
  200. {
  201. }
  202.  
  203. //------------------------------------------------------------------------------
  204. //    • FW_CRegionShapeRep::FW_CRegionShapeRep
  205. //------------------------------------------------------------------------------
  206.  
  207. FW_CRegionShapeRep::FW_CRegionShapeRep(XMPShape* xmpShape) :
  208.     FW_CShapeRep(gGraphicGlobales.gRegion),
  209.     fXMPShape(::NewXMPShape(xmpShape))
  210. {
  211. }
  212.  
  213. //------------------------------------------------------------------------------
  214. //    • FW_CRegionShapeRep::FW_CRegionShapeRep
  215. //------------------------------------------------------------------------------
  216.  
  217. FW_CRegionShapeRep::FW_CRegionShapeRep(const FW_CRect& rect) :
  218.     FW_CShapeRep(gGraphicGlobales.gRegion),
  219.     fXMPShape(::NewXMPShape(rect))
  220. {
  221. }
  222.  
  223. //------------------------------------------------------------------------------
  224. //    • FW_CRegionShapeRep::~FW_CRegionShapeRep
  225. //------------------------------------------------------------------------------
  226.  
  227. FW_CRegionShapeRep::~FW_CRegionShapeRep()
  228. {
  229.     delete fXMPShape;
  230.     fXMPShape = NULL;
  231. }
  232.  
  233. //------------------------------------------------------------------------------
  234. //    • FW_CRegionShapeRep::Draw
  235. //------------------------------------------------------------------------------
  236.  
  237. void FW_CRegionShapeRep::Draw(FW_CGraphicContext* graphicContext)
  238. {
  239.     FW_ShapeFills shapeFill = GetShapeFill();
  240.  
  241.     if (shapeFill == FW_kNullShape || fXMPShape == NULL)
  242.         return;
  243.     
  244.     FW_PlatformRegion region = graphicContext->AsPlatformRegion(fXMPShape);
  245.     
  246. #ifdef FW_BUILD_MAC
  247.     graphicContext->SelectInkAndStyle(GetShapeInk(), GetShapeStyle(), FW_kGeometricShape, shapeFill);
  248.     
  249.     if (shapeFill == FW_kFramed)
  250.         ::FrameRgn(region);
  251.     else
  252.         ::PaintRgn(region);
  253. #endif
  254. #ifdef FW_BUILD_WIN
  255.     FW_CWinBrush brush(GetShapeInk(), GetShapeStyle());    
  256.     
  257.     if (shapeFill == FW_kFramed)
  258.     {
  259.         XMPCoordinate penSize = GetShapeStyle()->GetPenSize();
  260.         FW_SPlatformPoint point = graphicContext->GetPlatformPoint(FW_CPoint(penSize, penSize));
  261.         ::FrameRgn(graphicContext->GetDC(), region, brush->GetGDIObject(), point.x, point.y);
  262.     }
  263.     else
  264.         ::FillRgn(graphicContext->GetDC(), region, brush->GetGDIObject());
  265. #endif
  266. }
  267.  
  268. //------------------------------------------------------------------------------
  269. //    • FW_CRegionShapeRep::DrawRegion
  270. //------------------------------------------------------------------------------
  271.  
  272. void FW_CRegionShapeRep::DrawRegion(FW_CGraphicContext* graphicContext,
  273.                                     XMPShape* xmpShape)
  274. {
  275.     if (gGraphicGlobales.gRegion.fFill == FW_kNullShape)
  276.         return;
  277.  
  278.     FW_PlatformRegion region = graphicContext->AsPlatformRegion(xmpShape);
  279.  
  280. #ifdef FW_BUILD_MAC
  281.     graphicContext->SelectInkAndStyle(gGraphicGlobales.gRegion.fInk, gGraphicGlobales.gRegion.fStyle, FW_kGeometricShape, gGraphicGlobales.gRegion.fFill);
  282.  
  283.     if (gGraphicGlobales.gRegion.fFill == FW_kFramed)
  284.         ::FrameRgn(region);
  285.     else
  286.         ::PaintRgn(region);
  287. #endif
  288. #ifdef FW_BUILD_WIN
  289.     FW_CWinBrush brush(defaultRegion->GetShapeInk(), defaultRegion->GetShapeStyle());    
  290.  
  291.     if (gGraphicGlobales.gRegion.fFill == FW_kFramed)
  292.     {
  293.         XMPCoordinate penSize = gGraphicGlobales.gRegion.fStyle->GetPenSize();
  294.         FW_SPlatformPoint point = graphicContext->GetPlatformPoint(FW_CPoint(penSize, penSize));
  295.         ::FrameRgn(graphicContext->GetDC(), region, brush->GetGDIObject(), point.x, point.y);
  296.     }
  297.     else
  298.         ::FillRgn(graphicContext->GetDC(), region, brush->GetGDIObject());
  299. #endif
  300. }
  301.  
  302. //------------------------------------------------------------------------------
  303. //    • FW_CRegionShapeRep::GetShapeBounds
  304. //------------------------------------------------------------------------------
  305.  
  306. FW_CRect FW_CRegionShapeRep::GetShapeBounds() const
  307. {
  308.     FW_CRect bounds(0, 0, 0, 0);
  309.  
  310.     if (fXMPShape)
  311.         fXMPShape->GetBoundingBox(&bounds);
  312.     
  313.     return bounds;
  314. }
  315.  
  316. //------------------------------------------------------------------------------
  317. //    • FW_CRegionShapeRep::Transform
  318. //------------------------------------------------------------------------------
  319.  
  320. void FW_CRegionShapeRep::Transform(XMPTransform* transform)
  321. {
  322.     if (fXMPShape)
  323.         fXMPShape->Transform(transform);
  324. }
  325.  
  326. //------------------------------------------------------------------------------
  327. //    • FW_CRegionShapeRep::InverseTransform
  328. //------------------------------------------------------------------------------
  329.  
  330. void FW_CRegionShapeRep::InverseTransform(XMPTransform* transform)
  331. {
  332.     if (fXMPShape)
  333.         fXMPShape->InverseTransform(transform);
  334. }
  335.  
  336. //------------------------------------------------------------------------------
  337. //    • FW_CRegionShapeRep::MoveShape
  338. //------------------------------------------------------------------------------
  339.  
  340. void FW_CRegionShapeRep::MoveShape(XMPCoordinate deltaX, XMPCoordinate deltaY)
  341. {
  342.     if (fXMPShape)
  343.     {
  344.         XMPTransform *trans = ::NewXMPTransform(FW_CPoint(deltaX, deltaY));
  345.         fXMPShape->Transform(trans);
  346.         delete trans;
  347.     }
  348. }
  349.  
  350. //------------------------------------------------------------------------------
  351. //    • FW_CRegionShapeRep::MoveShapeTo
  352. //------------------------------------------------------------------------------
  353.  
  354. void FW_CRegionShapeRep::MoveShapeTo(XMPCoordinate x, XMPCoordinate y)
  355. {
  356.     if (fXMPShape)
  357.     {
  358.         FW_CRect bounds;
  359.         fXMPShape->GetBoundingBox(&bounds);    
  360.         MoveShape(x - bounds.left, y - bounds.top);
  361.     }
  362. }
  363.  
  364. //------------------------------------------------------------------------------
  365. //    • FW_CRegionShapeRep::SetXMPShape
  366. //------------------------------------------------------------------------------
  367.  
  368. void FW_CRegionShapeRep::SetXMPShape(XMPShape* xmpShape)
  369. {
  370.     if (xmpShape)
  371.         fXMPShape->CopyFrom(xmpShape);
  372.     else
  373.     {
  374.         delete fXMPShape;
  375.         fXMPShape = NULL;
  376.     }
  377.     Changed();
  378. }
  379.  
  380. //------------------------------------------------------------------------------
  381. //    • FW_CRegionShapeRep::SetAsDefault
  382. //------------------------------------------------------------------------------
  383.  
  384. void FW_CRegionShapeRep::SetAsDefault() const
  385. {
  386.     SetDefaultProperties(gGraphicGlobales.gRegion);
  387. }
  388.  
  389. //------------------------------------------------------------------------------
  390. //    • FW_CRegionShapeRep::HitTest
  391. //------------------------------------------------------------------------------
  392.  
  393. FW_HitTestPart FW_CRegionShapeRep::HitTest(const FW_CPoint& test) const
  394. {
  395.     return FW_kOutside;
  396. }
  397.  
  398. //------------------------------------------------------------------------------
  399. //    • FW_CRegionShapeRep::Copy
  400. //------------------------------------------------------------------------------
  401.  
  402. FW_CRegionShape FW_CRegionShapeRep::Copy() const
  403. {
  404.     XMPShape *shape;
  405.     if (fXMPShape == NULL)
  406.         shape = ::NewXMPShape();
  407.     else
  408.         shape = ::NewXMPShape(fXMPShape);
  409.         
  410.     FW_CRegionShape region(shape);
  411.     return region;
  412. }
  413.  
  414. //----------------------------------------------------------------------------------------
  415. //    • FW_CRegionShapeRep::Flatten
  416. //----------------------------------------------------------------------------------------
  417.  
  418. void FW_CRegionShapeRep::Flatten(FW_CWritableStream& stream)
  419. {
  420. FW_UNUSED(stream);
  421.     // NotYetImplemented();
  422. }
  423.  
  424. //----------------------------------------------------------------------------------------
  425. //    • FW_CRegionShapeRep::Unflatten
  426. //----------------------------------------------------------------------------------------
  427.  
  428. void FW_CRegionShapeRep::Unflatten(FW_CReadableStream& stream)
  429. {
  430. FW_UNUSED(stream);
  431.     // NotYetImplemented();
  432. }
  433.